﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Command.cs" company="Sitecore A/S">
//   Copyright (C) by Sitecore A/S
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace AurelienRibon.Ui.Terminal
{
  /// <summary>The command.</summary>
  public class Command
  {
    #region Constructors and Destructors

    /// <summary>Initializes a new instance of the <see cref="Command"/> class.</summary>
    /// <param name="raw">The raw.</param>
    /// <param name="name">The name.</param>
    /// <param name="args">The args.</param>
    public Command(string raw, string name, string[] args)
    {
      this.Raw = raw;
      this.Name = name;
      this.Args = args;
    }

    #endregion

    #region Public Properties

    /// <summary>Gets the args.</summary>
    public string[] Args { get; set; }

    /// <summary>Gets the name.</summary>
    public string Name { get; private set; }

    /// <summary>Gets the raw.</summary>
    public string Raw { get; set; }

    #endregion

    #region Public Methods

    /// <summary>The get description.</summary>
    /// <param name="commandFormat">The command format.</param>
    /// <param name="firstArgFormat">The first arg format.</param>
    /// <param name="otherArgsFormat">The other args format.</param>
    /// <param name="end">The end.</param>
    /// <returns>The System.String.</returns>
    public string GetDescription(string commandFormat, string firstArgFormat, string otherArgsFormat, string end)
    {
      var ret = string.Format(commandFormat, this.Name);
      if (this.Args.Length > 0)
      {
        ret += string.Format(firstArgFormat, this.Args[0]);
      }

      for (var i = 1; i < this.Args.Length; i++)
      {
        ret += string.Format(otherArgsFormat, this.Args[i]);
      }

      return ret + end;
    }

    #endregion
  }
}